package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SpBmlist;
import com.ruoyi.system.service.ISpBmlistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报名Controller
 * 
 * @author ruoyi
 * @date 2022-11-11
 */
@RestController
@RequestMapping("/api/bmlist")
public class SpBmlistApiController extends BaseController
{
    @Autowired
    private ISpBmlistService spBmlistService;

    /**
     * 查询报名列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SpBmlist spBmlist)
    {
        startPage();
        List<SpBmlist> list = spBmlistService.selectSpBmlistListWeb(spBmlist);
        return getDataTable(list);
    }

    /**
     * 导出报名列表
     */
    @Log(title = "报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpBmlist spBmlist)
    {
        List<SpBmlist> list = spBmlistService.selectSpBmlistListWeb(spBmlist);
        ExcelUtil<SpBmlist> util = new ExcelUtil<SpBmlist>(SpBmlist.class);
        util.exportExcel(response, list, "报名数据");
    }

    /**
     * 获取报名详细信息
     */
    @GetMapping(value = "/{bmId}")
    public AjaxResult getInfo(@PathVariable("bmId") Long bmId)
    {
        return AjaxResult.success(spBmlistService.selectSpBmlistByBmId(bmId));
    }

    /**
     * 新增报名
     */
    @Log(title = "报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpBmlist spBmlist)
    {
        return toAjax(spBmlistService.insertSpBmlist(spBmlist));
    }

    /**
     * 修改报名
     */
    @Log(title = "报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpBmlist spBmlist)
    {
        return toAjax(spBmlistService.updateSpBmlist(spBmlist));
    }

    /**
     * 删除报名
     */
    @Log(title = "报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bmIds}")
    public AjaxResult remove(@PathVariable Long[] bmIds)
    {
        return toAjax(spBmlistService.deleteSpBmlistByBmIds(bmIds));
    }
}
